//
//  CHGridViewColCell.swift
//  CertManageSdk
//
//  Created by cyptt on 2023/3/16.
//

import UIKit

public class CHGridViewColCell: UICollectionViewCell {
    
//    var gridModel:CHGridModel?
    private var clickItemCallBack:((_ index:Int) -> ())?
    private var index:Int = 0
    lazy var btn = {()-> UIButton in
        let btn:UIButton =  UIButton.init(type:UIButton.ButtonType.custom)
        btn.backgroundColor = UIColor.clear
        btn.frame = self.bounds
        btn.addTarget(self, action: #selector(btnClick(btn: )), for: UIControl.Event.touchUpInside)
        return btn
    }()
    
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.setUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    public override  func awakeFromNib() {
        super.awakeFromNib()
      
        self.setUI()
        
    }
    
    func setUI(){
        self.addSubview(self.btn)
     
       
    }
    
//    func setGridModel(model:CHGridModel?){
//        
//    
//        self.gridModel = model
//        btn.setTitle(model?.title, for: .normal)
//        let image:UIImage? = model?.iconImage
//      
//        btn.setImage(image, for: .normal)
//        
//        btn.setTitleColor(model?.titleColor, for: .normal)
//        btn.titleLabel?.font = model?.titleFont
//        self.backgroundColor = self.gridModel?.cellBgColor
//        
//        var position:BUTTON_IMAGE_LOCAL_TYPE = .top
//        if model?.imgPosition == .top{
//            position = .top
//        }else if model?.imgPosition == .left{
//            position = .left
//        }else if model?.imgPosition == .right{
//            position = .right
//        }else if model?.imgPosition == .bottom{
//            position = .bottom
//        }
//      
//        self.btn.imageLocal(local:position , margin: model?.margin ?? 10)
//        
//        if model?.cellHandelr != nil{
//            model?.cellHandelr!(self)
//        }
// 
//    }
    
    /*
     确定回调
     */
    public func itemClickCallBack(clouse:@escaping(_ index:Int)-> Void,index:Int){
        self.clickItemCallBack = clouse
        self.index = index
    }
    
    
    
    @objc func btnClick(btn:UIButton){
        
        if self.clickItemCallBack != nil {
            self.clickItemCallBack!(self.index)
        }
    }
    
   
}
